<?php
	require_once('paths.inc');
	require_once(INCLUDE_PATH.'constants.inc');
	require_once('page.inc');
	require_once(DB_PATH.'db.inc');
	
	require_once('security.inc');
    require_once('utils.inc');
	
	session_start();
	check_permissions(CT_PERM_COMENZI);
	html_header("LANG_View_Comanda", null, "view_comanda");

	//luat din URL id=ul comenzii
	$id = $_GET['id'];
		
	$id_client = $_SESSION['user_logat']->id_client;
	
	if (isset($id) && !empty($id)) {
		//edit
		$db = db_connect();
		try {
			$_SESSION['comanda'] = Comanda::queryLoadByIdWithAllData($db, $id, $id_client);				
		}
		catch (QueryLoadComandaException $e) {								
			redirectOnError(CT_LOAD_COMANDA_BY_ID);				
		}
		catch (QueryLoadFirmaException $e) {
			redirectOnError(CT_LOAD_COMANDA_BY_ID);
		}
	}
	else {
		// trebuie semnala cumva eroare
	}		

	$linkuri = array(LANG_Home => "home.php", LANG_Comenzi => "show_comenzi.php", LANG_Show_comanda => "");	
	titlu_pagina($linkuri);
    output_notice_msg();
    output_extra_text(LANG_EXTRA_VIEW_COMANDA);	

	view_comanda($_SESSION['comanda'], $currencies);
	echo '<input type="hidden" value="' . $id . '" id="id_comanda" />';

	html_footer(); 
?>